package com.heh.mybatisplus;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.heh.mybatisplus.entity.RoleMenuEntity;
import com.heh.mybatisplus.service.RoleMenuService;
import com.heh.mybatisplus.service.impl.RoleMenuServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

@MapperScan("com.heh.mybatisplus.mapper")
@SpringBootApplication
@Slf4j
public class MybatisPlusEduApplication implements ApplicationRunner {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private RoleMenuService roleMenuService;

    void query() throws JsonProcessingException {
        List<RoleMenuEntity> list = roleMenuService.list();
        log.info("list:{}", objectMapper.writeValueAsString(list));

    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        query();
    }


    public static void main(String[] args) {
        SpringApplication.run(MybatisPlusEduApplication.class, args);
    }

}
